public class SearchInsertPosition {
    public int searchInsert(int[] nums, int target) {
        int n = nums.length;
        int left = 0, right = n - 1;
        if(nums[right] < target) {
            return right + 1;
        }

        while(left < right) {
            int mid = left + ((right - left) >> 1);
            if(nums[mid] < target) {
                left = mid + 1;
            }else {
                right = mid;
            }
        }

        return left;
    }
}
